package com.lagou.work.task03.angel.utils;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author：dingyuan
 * @date：2022.4.6 21:15
 * @description：解析Properties文件工具类
 * @version: 1.0
 */
public class ParsePropertiesFileUtil {

    public Map<String, String> readProperties(String path){

        Properties properties = new Properties();

        Map<String, String> propMap =  new HashMap<>();

        try{

            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path);

            Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);

            properties.load(reader);

        }catch(Exception e){

            e.printStackTrace();

        }

        for(Map.Entry<Object,Object> entries : properties.entrySet()){

            propMap.put((String)entries.getKey(),(String)entries.getValue());

        }

        return  propMap;

    }
}
